package com.adou.jdbc;

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @description:JDBC DML和DCL
 * @author:
 * @version: JDBCDemo.java v 0.1
 * @date: 2023.04.01
 */
public class JDBCDemo3 {
    public static void main(String[] args) throws Exception {
        //DML
        test1();

        //DDL
//        不一定有返回数据


    }

    /***
     * @Description //DML
     *
     * @Param
     * @return
     * @Date
     * @Author wj
     **/
    public static void test1() throws Exception {
        // 1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        // 2.获取连接

        String url = "jdbc:mysql://127.0.0.1:3306/db1";
        String username = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, username, password);

        // 3.sql
        String sql = "update account set money = 2000 where id = 5";

        // 4。获取执行sql对象
        Statement statement = connection.createStatement();

        // 5.执行sql
        int count = statement.executeUpdate(sql);// 执行DML，受影响行数

        // 6.处理结果
//        System.out.println(result);
        if(count > 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }


        // 7.释放资源
        statement.close();
        connection.close();
    }

}
